package com.xfcy.blog.controller.web;

import com.xfcy.blog.annotation.BusinessLogger;
import com.xfcy.blog.common.R;
import com.xfcy.blog.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 前台文章管理器
 *
 * @author 晓风残月Lx
 * @date 2023/4/9 22:07
 */
@RestController
@RequestMapping("/web/article")
@Api(tags = "前台文章管理")
public class WebArticleController {

    @Resource
    private ArticleService articleService;

    @BusinessLogger(value = "首页-用户访问首页",type = "查询",desc = "查询所有文章")
    @GetMapping("/list")
    @ApiOperation(value = "文章列表", httpMethod = "GET", response = R.class, notes = "文章列表")
    public R list(@RequestParam Integer pageNo, Integer pageSize) {
        return articleService.listWebArticle(pageNo, pageSize);
    }

    @BusinessLogger(value = "首页-文章搜索",type = "查询",desc = "文章搜索")
    @GetMapping(value = "/searchArticle")
    @ApiOperation(value = "文章搜索", httpMethod = "GET", response = R.class, notes = "文章搜索")
    public R searchArticle(String keywords) {
        return articleService.searchArticle(keywords);
    }


    @BusinessLogger(value = "门户-用户查看文章详情", type = "查询", desc = "查看文章详情")
    @GetMapping("/info")
    @ApiOperation(value = "文章详情", httpMethod = "GET", response = R.class, notes = "文章详情")
    public R getArticle(Long id) {
        return articleService.webArticleInfo(id);
    }

    @BusinessLogger(value = "分类标签文章列表", type = "查询", desc = "分类标签文章列表")
    @GetMapping("/condition")
    @ApiOperation(value = "分类标签文章列表", httpMethod = "GET", response = R.class, notes = "分类标签文章列表")
    public R condition(Long categoryId, Long tagId, Integer pageNo, @RequestParam(defaultValue = "6") Integer pageSize) {
        return articleService.condition(categoryId, tagId, pageNo, pageSize);
    }

    @BusinessLogger(value = "首页-归档", type = "查询", desc = "归档")
    @GetMapping("/archive")
    @ApiOperation(value = "归档", httpMethod = "GET", response = R.class, notes = "归档")
    public R archive(Integer pageNo, Integer pageSize) {
        return articleService.archive(pageNo, pageSize);
    }

    @BusinessLogger(value = "门户-文章点赞", type = "更新", desc = "文章点赞")
    @GetMapping("/articleLike")
    @ApiOperation(value = "文章点赞", httpMethod = "GET", response = R.class, notes = "文章点赞")
    public R articleLike(Integer articleId) {
        return articleService.articleLike(articleId);
    }

    // TODO 微信公众号

}
